package cn.elwy.rcp.ui.wizard;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.KeyEvent;
import org.eclipse.swt.events.KeyListener;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Control;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;

import cn.elwy.rcp.ui.wizard.BaseWizardPage;

public class WizardPageOne extends BaseWizardPage {

  private Text text1;
  private Composite container;

  /**
   * Create the wizard.
   */
  public WizardPageOne() {
    super("First Page");
    setTitle("First Page2");
    setDescription("This wizard does not really do anything. But this is the first page");
  }

  /**
   * Create contents of the wizard.
   * 
   * @param parent
   */
  public void createControl(Composite parent) {
    // Composite container = new Composite(parent, SWT.NULL);

    container = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout();
    container.setLayout(layout);
    layout.numColumns = 2;
    Label label1 = new Label(container, SWT.NULL);
    label1.setText("Put here a value");

    text1 = new Text(container, SWT.BORDER | SWT.SINGLE);
    text1.setText("");
    text1.addKeyListener(new KeyListener() {

      public void keyPressed(KeyEvent e) {
        // TODO Auto-generated method stub

      }

      public void keyReleased(KeyEvent e) {
        if (!text1.getText().equals(new String())) {
          setPageComplete(true);

        }

      }

    });

    GridData gd = new GridData(GridData.FILL_HORIZONTAL);
    text1.setLayoutData(gd);
    // Required to avoid an error in the system
    setControl(container);
    setPageComplete(false);

    // setControl(container);
  }

  public String getText1() {
    return text1.getText();

  }

  // You need to overwrite this method otherwise you receive a
  // AssertionFailedException
  // This method should always return the top widget of the application

  public Control getControl() {
    return container;

  }

  /*
   * (non-Javadoc)
   * @see cn.elwy.rcp.ui.wizard.BaseWizardPage#nextButtonPressed()
   */
  public boolean nextButtonPressed() {

    return super.nextButtonPressed();
  }
}
